Kenneth Tay
Oct 16, 2018
ggplot2
dplyr
selectmutatearrangefiltersummarizegroup_byreadr“Official” cheat sheet for readr available here.
The most important syntax in R is the function call. All R syntax has function calls underlying it.
function_name(<inputs to the function>,
<arguments which change
how the function operates>)x <- c(-5, -3, -1, 1, 3, NA)
mean(x, na.rm = TRUE)## [1] -1
abs(x): If x is positive, return x. If x is negative, return x without the negative sign.
mean(abs(x), na.rm = TRUE)## [1] 2.6
abs(x): If x is positive, return x. If x is negative, return x without the negative sign.
mean(abs(x), na.rm = TRUE)## [1] 2.6
%>% syntax with dplyrTake the mtcars dataset, select just the wt and mpg columns, then select rows with mpg < 15
mtcars %>%
select(wt, mpg) %>%
filter(mpg < 15)+ syntax with ggplot2library(ggplot2)
ggplot(data = mtcars, mapping = aes(x = wt, y = hp)) +
geom_point() +
labs(title = "Horsepower vs. Weight", x = "Weight",
y = "Horsepower") +
theme_classic()dplyr), you have to reload themgetwd()None to D4: drought levels of increasing severity
Optional material
readr)readxl)haven)DBI)jsonlite)xml2)httr)rvest)tidyr functions: gather and spreadgather: Used when some column names are not variables, but values of a variable
spread: Opposite of gather
tidyr functions: separate and uniteseparate: Used to separate values in one column into multiple columns
unite: Opposite of separate